//
//  DadaViewController.m
//  news
//
//  Created by imacbookair on 16/3/14.
//  Copyright © 2016年 imacbookair. All rights reserved.
//

#import "DadaViewController.h"

@interface DadaViewController ()<UIWebViewDelegate>

@end

@implementation DadaViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    UIWebView *wv = [[UIWebView alloc]initWithFrame:CGRectMake(0, -50, self.view.bounds.size.width, self.view.bounds.size.height)];
    NSString *url = self.str;
    [wv loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
    
    wv.delegate = self;
    
    self.tabBarController.tabBar.hidden = YES;
    [wv NightWithType:UIViewColorTypeNormal];
    
    [self.view addSubview:wv];
}


- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    //webview加载页面后，改变字体的大小，当字体变大的时候页面会随着变大，但是当我缩小字体的时候页面还是原来的大小。
    NSString * srt = @"document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust = '120%'";
    [webView stringByEvaluatingJavaScriptFromString:srt];
    [webView stringByEvaluatingJavaScriptFromString:
     //document.createElement()是在对象中创建一个对象 要与appendChild() 或 insertBefore()方法联合使用。其中，appendChild() 方法在节点的子节点列表末添加新的子节点。insertBefore() 方法在节点的子节点列表任意位置插入新的节点。
     //JavaScript文件的动态加载
     @"var script = document.createElement('script');"
     "script.type = 'text/javascript';"
     "script.text = \"function ResizeImages() { "
     //缩放图片到合适大小
     "var myimg,oldwidth;"
     "var maxwidth=320;" //缩放系数 图片宽度
     //遍历所有image
     "for(i=0;i <document.images.length;i++){"
     "myimg = document.images[i];"
     //WebView加载HTML图片大小自适应与文章自动换行”
     "if(myimg.width > maxwidth){"
     "oldwidth = myimg.width;"
     "myimg.width = maxwidth;"
     "myimg.height = myimg.height * (maxwidth/oldwidth);"
     "}"
     "}"
     "}\";"
     "document.getElementsByTagName('head')[0].appendChild(script);"];
    
    [webView stringByEvaluatingJavaScriptFromString:srt];
    
    //字体颜色
    [webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('body')[0].style.webkitTextFillColor= 'black'"];
    //页面背景色
    
    [webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('body')[0].style.background ='wihte'"];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
